# coding:utf-8
import time

from lib.base import Base
from page.android import train_rush_order_fill_page, train_index_page, train_rush_ticket_order_list_page

__author__ = 'weixin.yuan'


class TrainRushOrderFill(Base):
    """抢票订单填写"""
    def __init__(self, method_name):
        Base.__init__(self, method_name)

        """
        本页元素
        """
        self.rush_ticket_title = train_rush_order_fill_page.elements['填写抢票信息title']
        self.qbxz_btn = train_rush_order_fill_page.elements['抢票须知']
        self.qbxz_title = train_rush_order_fill_page.elements['云抢票功能说明']
        self.zdcc_btn = train_rush_order_fill_page.elements['指定车次']
        self.xzcc_btn = train_rush_order_fill_page.elements['选择车次']
        self.yes_btn = train_rush_order_fill_page.elements['确定']
        self.seat_list = train_rush_order_fill_page.elements['座位列表']
        self.tj_chengke_btn = train_rush_order_fill_page.elements['添加乘客']
        self.tj_ertong_btn = train_rush_order_fill_page.elements['添加儿童']
        self.xz_chengke_btn = train_rush_order_fill_page.elements['账号本人']
        self.qdtj_chengke_btn = train_rush_order_fill_page.elements['确定添加乘客']
        self.lxr_btn = train_rush_order_fill_page.elements['联系人']
        self.mobile_btn = train_rush_order_fill_page.elements['手机号']
        self.mobile_input = train_rush_order_fill_page.elements['通知出票信息']
        self.next_btn = train_rush_order_fill_page.elements['下一步']
        self.rush_ticket_success_rate_title = train_rush_order_fill_page.elements['抢票成功率估算title']
        self.jisu_rush_btn = train_rush_order_fill_page.elements['极速抢票']
        self.kuaisu_rush_btn = train_rush_order_fill_page.elements['快速抢票']
        self.no_need_btn = train_rush_order_fill_page.elements['不需要']
        self.order_payment_title = train_rush_order_fill_page.elements['订单支付title']

        """
        外部页面元素
        """
        # self.rush_ticket_btn = train_index_page.elements['抢票按钮']
        # self.add_rush_ticket_btn = train_rush_ticket_order_list_page.elements['添加抢票按钮']

    def test_rush_order_fill(self):
        """抢票订单填写"""
        self.open_schema_android('6011')
        self.check(self.rush_ticket_title)

        self.click(self.qbxz_btn)  # 抢票须知
        self.check(self.qbxz_title)
        self.back()

        self.click(self.zdcc_btn)
        time.sleep(5)
        self.click(self.xzcc_btn)
        self.click(self.yes_btn)

        for btn in self.seat_list:
            self.click(btn, times=1, is_necessary=False)
        self.click(self.yes_btn)

        if self.is_exits(self.tj_chengke_btn, times=2):
            self.click(self.tj_chengke_btn)
            self.click(self.xz_chengke_btn)
            self.click(self.qdtj_chengke_btn)

        if self.is_exits(self.mobile_input):
            self.click(self.lxr_btn)
            self.click(self.mobile_btn)

        self.click(self.next_btn)
        self.check(self.rush_ticket_success_rate_title)

        if self.is_exits(self.kuaisu_rush_btn, times=10):
            self.click(self.kuaisu_rush_btn)
        else:
            self.click(self.jisu_rush_btn)
        self.click(self.no_need_btn)
        self.check(self.order_payment_title)
